package com.xbongbong.saas.enums;

import com.xbongbong.paas.enums.FieldTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @date 2023/02/16 19:01
 */
@Getter
public enum  TriggerConditionBusinessFieldEnum {

    /**
     * 工单v2
     * 工单编号、工单名称、关联客户、优先级、预计开始时间、预计结束时间、地址、工单状态、当前节点、接受时间、结束时间、处理时长、入池时间、入池次数、取消原因、移交原因、拒绝原因、当前sla是否达标、整体sla是否达标、匹配SLA次数、评分、创建人、创建时间、更新时间
     */
    WORK_ORDER_V2(XbbRefTypeEnum.WORK_ORDER_V2.getCode(), Arrays.asList(FieldTypeEnum.SERIALNO.getAlias(), "text_1", "text_2", "text_3", "date_1", "date_2", "address_1", "text_4", "date_5", "num_7", "date_7", "num_1", "text_8", "text_9", "text_10", "num_2", "text_11", "text_12", "num_3", FieldTypeEnum.CREATORID.getAlias(), FieldTypeEnum.ADDTIME.getAlias(), FieldTypeEnum.UPDATETIME.getAlias())),

    ;

    /**
     * 业务类型
     */
    private int code;

    /**
     * 字段数组
     */
    private List<String> attrArray;

    TriggerConditionBusinessFieldEnum (int code,List<String> attrArray) {
        this.code = code;
        this.attrArray = attrArray;
    }

    /**
     * 根据业务类型查询所有字段
     * @param code
     * @return
     */
    public static List<String> getAttrsByCode (Integer code) {
        List<String> array = new ArrayList<>();
        for (TriggerConditionBusinessFieldEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                return cacheCode.getAttrArray();
            }
        }
        return array;
    }
}
